#
import redis

r = redis.Redis(host='localhost', port=6379, db=0)

def splitHost(netloc):
    us = netloc.split(':', 1)
    if len(us) == 2:
        host, port = us
    else:
        host, port = netloc, None
    return host, port

def joinHost(host, port):
    return '%s:%s' %(host, port) if port else host

# data interface
def urlGet(key):
    return r.hget("urls", key)

def urlSet(key, val):
    return r.hset("urls", key, val)

def infoGet(key):
    return r.hget("clicks", key)

def infoUpdate(key):
    return r.hincrby("clicks", key)
